cmake_minimum_required(VERSION 3.10)
project(vvxfwm4)

include (cmake/my_utils.cmake)


option(HAVE_COMPOSITOR "Define to enable compositor" ON)
option(HAVE_PRESENT_EXTENSION "Define to enable xpresent" ON)
option(HAVE_EPOXY "Define to enable epoxy" ON)
option(HAVE_XI2 "Define to enable XI2" ON)
option(HAVE_XSYNC "Define to enable xsync" ON)
option(HAVE_RENDER "Define to enable render" ON)
option(HAVE_RANDR "Define to enable xrandr" ON)
option(HAVE_XRES "Define to enable XRes" ON)

set(IS_ALONE_COMPILE TRUE)
if (NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
        set(IS_ALONE_COMPILE FALSE)
endif()

include(GNUInstallDirs)

set(PACKAGE_DATADIR ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME})

add_definitions(-DHAVE_LIBSTARTUP_NOTIFICATION)
add_definitions(-DDEBUG)
add_definitions(-DSHOW_POSITION)

find_package(PkgConfig)
#xfwm4_CFLAGS =								\
#	$(GLIB_CFLAGS) 							\
#	$(GTK_CFLAGS) 							\
#	$(COMPOSITOR_CFLAGS)						\
#	$(EPOXY_CFLAGS)							\
#	$(LIBSTARTUP_NOTIFICATION_CFLAGS)				\
#	$(LIBX11_CFLAGS)						\
#	$(LIBXFCE4KBD_PRIVATE_CFLAGS)					\
#	$(LIBXFCE4UI_CFLAGS)						\
#	$(LIBXFCE4UTIL_CFLAGS)						\
#	$(LIBXFCONF_CFLAGS)						\
#	$(PRESENT_EXTENSION_CFLAGS)					\
#	$(RANDR_CFLAGS)							\
#	$(RENDER_CFLAGS)						\
#	$(XINERAMA_CFLAGS)						\
#	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"				\
#	-DDATADIR=\"$(datadir)\"					\
#	-DHELPERDIR=\"$(HELPER_PATH_PREFIX)\"				\
#	-DPACKAGE_DATADIR=\"$(pkgdatadir)\"				\
#	-DG_LOG_DOMAIN=\"xfwm4\"

if (${IS_ALONE_COMPILE})
pkg_check_modules(GLIB IMPORTED_TARGET glib-2.0)
pkg_check_modules(GTK IMPORTED_TARGET gtk+-3.0)
pkg_check_modules(XFCE4_UI IMPORTED_TARGET libxfce4ui-2)
# pkg_check_modules(XFCONF IMPORTED_TARGET libxfconf-0)
pkg_check_modules(XFCE4_KBD_PRIVATE IMPORTED_TARGET libxfce4kbd-private-3)
pkg_check_modules(XFCE4_UTIL IMPORTED_TARGET libxfce4util-1.0)
endif()

pkg_check_modules(XPRESENT IMPORTED_TARGET xpresent)
pkg_check_modules(XRENDER IMPORTED_TARGET xrender)
pkg_check_modules(XINERAMA IMPORTED_TARGET xinerama)
pkg_check_modules(XEXT IMPORTED_TARGET xext)
pkg_check_modules(XCOMPOSITE IMPORTED_TARGET xcomposite)
pkg_check_modules(EPOXY IMPORTED_TARGET epoxy)
pkg_check_modules(X11 IMPORTED_TARGET x11)
pkg_check_modules(STARTUP_NOTIFICATION IMPORTED_TARGET libstartup-notification-1.0)
if (HAVE_COMPOSITOR)
pkg_check_modules(XFIXES IMPORTED_TARGET xfixes)
pkg_check_modules(XDAMAGE IMPORTED_TARGET xdamage)
endif()
if (HAVE_XI2)
pkg_check_modules(XI IMPORTED_TARGET xi)
endif()
if (HAVE_RANDR)
pkg_check_modules(XRANDR IMPORTED_TARGET xrandr)
endif()
if (HAVE_XRES)
pkg_check_modules(XRES IMPORTED_TARGET xres)
endif()

my_check_header_exists_and_define_macro("memory.h")
my_check_header_exists_and_define_macro("string.h")

#@SET_MAKE@
#
#ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
#
#EXTRA_DIST =								\
#	example.gtkrc-2.0						\
#	COMPOSITOR							\
#	README.md
#
#SUBDIRS = 								\
        # defaults 							\
#	helper-dialog 							\
#	icons 								\
#	common 								\
#	settings-dialogs						\
#	src 								\
#	themes								\
#	po
#
add_subdirectory(common)
add_subdirectory(src)
add_subdirectory(defaults)

set(_vvxfwm4_ ${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME})
configure_file(
        ${CMAKE_CURRENT_SOURCE_DIR}/vvxfwm4.desktop.in
        ${CMAKE_CURRENT_BINARY_DIR}/vvxfwm4.desktop
        @ONLY
)

install(FILES
        ${CMAKE_CURRENT_BINARY_DIR}/vvxfwm4.desktop
        DESTINATION /etc/xdg/autostart

)


#distclean-local:
#	rm -rf *.cache po/.intltool-merge-cache.lock
#
#.PHONY: ChangeLog
#
#ChangeLog: Makefile
#	(GIT_DIR=$(top_srcdir)/.git git log > .changelog.tmp \
#	&& mv .changelog.tmp ChangeLog; rm -f .changelog.tmp) \
#	|| (touch ChangeLog; echo 'Git directory not found: installing possibly empty changelog.' >&2)
#
#dist-hook: ChangeLog
#
#if MAINTAINER_MODE
#
#all-local: compile_flags.txt
#
#compile_flags.txt: Makefile
#	rm -f $@
#	for i in \
#	$(PLATFORM_CPPFLAGS) \
#	$(GLIB_CFLAGS)  \
#	$(GTK_CFLAGS)  \
#	$(COMPOSITOR_CFLAGS) \
#	$(EPOXY_CFLAGS) \
#	$(LIBSTARTUP_NOTIFICATION_CFLAGS) \
#	$(LIBX11_CFLAGS) \
#	$(LIBXFCE4KBD_PRIVATE_CFLAGS) \
#	$(LIBXFCE4UI_CFLAGS) \
#	$(LIBXFCE4UTIL_CFLAGS) \
#	$(LIBXFCONF_CFLAGS) \
#	$(PRESENT_EXTENSION_CFLAGS) \
#	$(RANDR_CFLAGS) \
#	$(RENDER_CFLAGS) \
#	$(XINERAMA_CFLAGS) \
#	-I${top_srcdir} \
#	-DHAVE_CONFIG_H=1 \
#	-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
#	-DDATADIR=\"$(datadir)\" \
#	-DHELPERDIR=\"$(HELPER_PATH_PREFIX)\" \
#	-DPACKAGE_DATADIR=\"$(pkgdatadir)\" \
#	-DG_LOG_DOMAIN=\"xfwm4\"; \
#	do \
#		echo "$$i" >> $@ || exit 1; \
#	done
#
#endif
